//
//  ActivityListTableViewCell.m
//  豆瓣2
//
//  Created by dllo on 15/11/6.
//  Copyright (c) 2015年 张鸿峰. All rights reserved.
//

#import "ActivityListTableViewCell.h"

#import "UIImageView+WebCache.h"

@implementation ActivityListTableViewCell

- (void)dealloc
{
    [_bigImageView release];
    [_imageV release];
    [_label release];
    [_imageVv release];
    [_timeImageView release];
    [_addressImageView release];
    [_addressLabel release];
    [_typeImageView release];
    [_typeLabel release];
    [_typeLabel2 release];
    [_intrestLabel release];
    [_joinLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatSubviews];
    }
    return self;
}

- (void)creatSubviews
{
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 375 - 20, 160)];
    self.imageV.image = [UIImage imageNamed:@"bg_eventlistcell.png"];
    [self.contentView addSubview:self.imageV];
    [self.imageV release];
    
    self.imageVv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 35, 375 - 20, 140)];
    self.imageVv.image = [UIImage imageNamed:@"bg_share_large.png"];
    [self.contentView addSubview:self.imageVv];
    [self.imageVv release];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(self.imageV.frame.origin.x + 5, self.imageV.frame.origin.y, 375 - 20 - 5, 40)];
    [self.contentView addSubview:self.label];
    [self.label release];
    
    self.timeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date.png"]];
    self.timeImageView.frame = CGRectMake(self.label.frame.origin.x + 5, self.label.frame.origin.y + self.label.frame.size.height + 5, 16, 16);
    [self.contentView addSubview:self.timeImageView];
    [self.timeImageView release];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.timeImageView.frame.origin.x + self.timeImageView.frame.size.width + 5, self.timeImageView.frame.origin.y - 8, 200, 30)];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel release];
    
    self.addressImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_spot.png"]];
    self.addressImageView.frame = CGRectMake(self.timeImageView.frame.origin.x, self.timeImageView.frame.origin.y + self.timeImageView.frame.size.height + 10, 16, 16);
    [self.contentView addSubview:self.addressImageView];
    [self.addressImageView release];
    
    self.typeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_catalog.png"]];
    self.typeImageView.frame = CGRectMake(self.addressImageView.frame.origin.x, self.addressImageView.frame.origin.y + self.addressImageView.frame.size.height + 10, 16, 16);
    [self.contentView addSubview:self.typeImageView];
    [self.typeImageView release];
    
    self.intrestLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.typeImageView.frame.origin.x, self.typeImageView.frame.origin.y + self.typeImageView.frame.size.height + 20, 60, 30)];
//    self.intrestLabel.text = @"感兴趣:";
    self.intrestLabel.textColor = [UIColor redColor];
    [self.contentView addSubview:self.intrestLabel];
    [self.intrestLabel release];
    
    self.joinLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.intrestLabel.frame.origin.x + self.intrestLabel.frame.size.width + 60, self.intrestLabel.frame.origin.y, 40, 30)];
//    self.joinLabel.text = @"参加:";
    [self.contentView addSubview:self.joinLabel];
    self.joinLabel.textColor = [UIColor redColor];
    [self.joinLabel release];
    
    self.typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.addressLabel.frame.origin.x, self.typeImageView.frame.origin.y - 8 , 40, self.addressLabel.frame.size.height)];
    [self.contentView addSubview:self.typeLabel];
    self.typeLabel.text = @"类型:";
    [self.typeLabel release];
    
    
    self.bigImageView = [[UIImageView alloc] initWithFrame:CGRectMake(250, 40, 110, 120)];
    self.bigImageView.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.bigImageView];
    [self.bigImageView release];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(330, 10, 24, 24);
    self.button.backgroundColor = [UIColor redColor];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
    
    
}

//点击勾选框:
- (void)buttonAction:(UIButton *)btn
{
    if (self.myActivityList.selected) {
        //2.点击按钮的时候加判断
        [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
        
    }
    else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }
    self.myActivityList.selected = !self.myActivityList.selected;
}



- (UILabel *)addressLabel
{
    if (_addressLabel == nil) {
        
        self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLabel.frame.origin.x, self.addressImageView.frame.origin.y - 8, self.timeLabel.frame.size.width, self.timeLabel.frame.size.height)];
        [self.contentView addSubview:self.addressLabel];
        [self.addressLabel release];
    }
    return _addressLabel;
}

- (UILabel *)typeLabel2
{
    if (_typeLabel2 == nil) {
        
        self.typeLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(self.typeLabel.frame.origin.x + self.typeLabel.frame.size.width + 10, self.typeImageView.frame.origin.y - 3 , 60, self.addressLabel.frame.size.height)];
        [self.contentView addSubview:self.typeLabel2];
        [self.typeLabel2 release];
    }
    return _typeLabel2;
}

- (void)setMyActivityList:(ActivityList *)myActivityList
{
    if (_myActivityList != myActivityList) {
        [_myActivityList release];
        _myActivityList = [myActivityList retain];
    }
    NSURL *url = [NSURL URLWithString:self.myActivityList.image];
    [self.bigImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
    
    self.label.text = myActivityList.title;
//    self.intrestLabel.text = myActivityList.wisher_count;
//    self.joinLabel.text = myActivityList.participant_count;
    self.intrestLabel.text = [NSString stringWithFormat:@"%@",myActivityList.wisher_count];
    self.joinLabel.text = [NSString stringWithFormat:@"%@",myActivityList.participant_count];
    
    //点击勾选框:
    //1.tableview上拉下拉会重用cell,所以需要在赋值的时候加判断
    [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    if (self.myActivityList.selected) {
        
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }
    
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
